#!/usr/bin/env python
# coding=utf-8
# 首页

import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import util
import common

class DefaultHandler(webapp.RequestHandler):
	def get(self):
		user = users.get_current_user()
		if user:
			if users.is_current_user_admin():
				self.response.headers["Content-Type"] = "text/html; charset=utf-8"
				self.response.out.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
						<title>%s</title>
						<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
						<link href="css/style.css" type="text/css" rel="stylesheet" />
						<script src="js/global.js" type="text/javascript" language="javascript"></script>
						<frameset rows="25,*" framespacing="0" border="1">
						<frame src="top" id="header-frame" name="header-frame" frameborder="no" scrolling="no" />
						<frameset cols="180, 10, *" framespacing="0" border="1" id="frame-body">
						<frame src="left" id="menu-frame" name="menu-frame" frameborder="no" scrolling="yes" />
						<frame src="drag" id="drag-frame" name="drag-frame" frameborder="no" scrolling="no" />
						<frame src="main" id="main-frame" name="main-frame" frameborder="no" scrolling="yes" />
						</frameset>
						</frameset>
					</head>
					<body />
					</html>""" % common.getAppName())
			else:
				common.writeNoPermissionMessage(self)
		else:
			self.redirect(users.create_login_url(self.request.uri))

def main():
	application = webapp.WSGIApplication([('/', DefaultHandler),
		('/default', DefaultHandler)],
		debug=True)
	util.run_wsgi_app(application)


if __name__ == '__main__':
	main()
